<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort();
    %>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>订单管理</title>
    <%--    <link rel="stylesheet" href="<%=basePath%>/css/bootstrap.min.css"/>--%>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
          integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <link rel="stylesheet" href="../layui/css/layui.css">
</head>
<body>
<%--<script type="text/javascript" src="js/jquery-2.0.3.min.js"></script>--%>
<%--<script type="text/javascript" src="js/bootstrap.min.js"></script>--%>
<script src="https://s3.pstatp.com/cdn/expire-1-M/jquery/3.2.1/jquery.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"
        integrity="sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd"
        crossorigin="anonymous"></script>

<script type="text/javascript">
    function fahuo(ordernum) {
        if($('#statu'+ordernum+'').next().text() == "发货"){
            $.post('${pageContext.request.contextPath}/order/orderServlet', {"op":"fahuo","opp":"4","ordernum":ordernum}, function(str){
                if(str != null){

                    alert("发货成功！！");
                    $('#statu'+ordernum+'').text("已发货");
                    $('#statu'+ordernum+'').next().children('a').text("删除")
                }

            });
        }else{
            $.post('${pageContext.request.contextPath}/order/orderServlet', {"op":"deleteOrder","ordernum":ordernum}, function(str){
                if(str != null){

                    alert("删除成功！！");
                    $('#statu'+ordernum+'').parent().remove();
                }

            });
        }


        <%--window.location.href = "${pageContext.request.contextPath}/order/orderServlet?op=fahuo&ordernum="--%>
        <%--    + ordernum;--%>
        <%--alert("发货成功！！");--%>
    }
    function orderlist(ordernum) {

        $.post('${pageContext.request.contextPath}/order/orderServlet', {"op":"orderlist","ordernum":ordernum}, function(str){

            layer.open({
                type: 1,
                content: ""+str//注意，如果str是object，那么需要字符拼接。
            });

        });

        // layui.use('layer', function(){
        //     var layer = layui.layer;
        //
        //     layer.msg(ordernum);
        // });

    }
</script>
<div>
    <p style="font-size: 30px; margin-top: 20px; margin-left: 30px">订单管理</p>
</div>
<hr
        style="height: 10px; border: none; border-top: 10px groove skyblue;"/>
<table class="table table-bordered table-hover"
       style="margin-left: 16px; width: 1580px">
    <tr>
        <th style="width: 100px">序号</th>
        <th style="width: 100px">订单编号</th>
        <th style="width: 250px">创建时间</th>
        <th style="width: 250px">客户账号</th>
        <th style="width: 200px">商品数量</th>
        <th style="width: 200px">支付金额</th>
        <th style="width: 200px">订单状态</th>
        <th style="width: 200px">操作</th>
    </tr>
    <c:forEach items="${orders}" var="os" varStatus="vs">

        <tr class="active">
            <td>${vs.index+1}</td>
            <td><a href="javascript:orderlist('${os.ordernum}')">${os.ordernum}</a></td>
            <td>${os.time}</td>
            <td>${os.user.username}</td>
            <td>${os.quantity}</td>
            <td>${os.money}</td>
            <c:if test="${os.status==0}">
                <td id="statu${os.ordernum}">未付款</td>
                <td><a href="javascript:fahuo('${os.ordernum}')">删除</a></td>
            </c:if>
            <c:if test="${os.status==1}">
                <td id="statu${os.ordernum}">已付款</td>
                <td><a href="javascript:fahuo('${os.ordernum}')">删除</a></td>
            </c:if>
            <c:if test="${os.status==2}">
                <td id="statu${os.ordernum}">未发货</td>
                <td><a href="javascript:fahuo('${os.ordernum}')">发货</a></td>
            </c:if>
            <c:if test="${os.status==3}">
                <td id="statu${os.ordernum}">已发货</td>
                <td><a href="javascript:fahuo('${os.ordernum}')">删除</a></td>
            </c:if>

        </tr>
    </c:forEach>
</table>
</body>
</html>

<script src="../layui/layui.js"></script>
<script>

</script>